<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 广告管理
 * @author www.dingwei.cn
 */
class Advert extends MY_Controller {
	
    public $mSetting = null; //临时定义一个 待删除

    /**
     * 初始化
     * User constructor.
     */
    public function __construct() {
        parent::__construct();
        $this->loadModel('AdmSettingModel', 'mSetting');
    }
	/**
	 * 首页
	 */
	public function index(){
		
		if($_POST){
			
			$vConf = array(
					array('type', '类型', 'required|in_list[1,2]'),
			);
			$this->formDataValidation($vConf);
			$url = post('url');
			$type = post('type');
			if($type == 1){
				$url = '';
			}
			
			$data = array(
						'app_advert_type' => post('type'), 
						'app_advert_url' => $url
			);
			$pic = post('pic');
			if($pic){
				$path = 'uploads/admin/advert';
				$tS = saveTempImg($pic, $path, false);
				if($tS === false){
					$this->ajaxReturn(0, '上传图片失败');
				}
				$data['app_advert'] = $tS;
			}
			
			if($this->mSetting->save($data)){
				$this->ajaxReturn(1, '保存成功');
			}
			
			$this->ajaxReturn(0, '保存失败');
		}
		
		$info = $this->mSetting->get('app_advert,app_advert_type,app_advert_url');
		$data = array('info' => $info);
		$this->view('setting/activity/index', $data, 'validation,webuploader');
	}
}

